package com.cskaoyan;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.junit.Test;

import java.util.Random;

/**
 * @author ：王李轶群
 * @description：TODO
 * @date ：5/10/22 4:57 PM
 */
public class AliyunSendSms {
    @Test
    public void sendSms(){
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5t8gpxPTCR6W58RnZq4u", "mVPbpbxia0JQotb7HyJAREV8QUuq8h");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId","cn-hangzhou");
        request.putQueryParameter("PhoneNumbers","15966309896");
        request.putQueryParameter("SignName","stone4j");
        request.putQueryParameter("TemplateCode","SMS_173765187");
        request.putQueryParameter("TemplateParam","{\"code\":\"12345\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test(){
        Random random = new Random();
        String code = "";
        for (int i = 0; i < 6; i++) {
            Integer num = random.nextInt(10);
            String s = num.toString();
            code+=s;
        }
        System.out.println(code);
    }
}
